home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
5
/
DINKDEMO
/
DINKCLAS
/
DWINDOW.C
< prev
next >
Wrap
Text File
|
1992-07-07
|
6KB
|
336 lines
/*
File: DWindow.c
Written by: Mark Gross
Copyright: ⌐ 1992 by Applied Technical Software, all rights reserved.
Use at your own risk.
*/
// the is the Class definition for the DWindow class
#include "DWindow.h"
#include "DDocument.h"
#include "DEventHandler.h"
DWindow::DWindow(void)
{
//stub!!
}
DWindow::~DWindow(void)
{
DisposHandle( fPrintRecord);
}
Boolean DWindow::Init(DDocument *doc, Boolean hasColorWindows)
{
WindowPtr prevFrontWindow;
Point corner;
Rect r;
SetRect(&r, 0,0,0,0);
fVOffSet = 0;
fHOffSet = 0;
//set up the print record with the last printer settings
fPrintRecord = (THPrint) NewHandle(sizeof(TPrint) );
if(fPrintRecord != NULL)
{
PrOpen();
PrintDefault(fPrintRecord);
PrClose();
}
prevFrontWindow = FrontWindow();
if(prevFrontWindow != NULL)
{
SetPort( prevFrontWindow);
corner.v = prevFrontWindow->portRect.top;
corner.h = prevFrontWindow->portRect.left;
LocalToGlobal(&corner);
}
fDoc = doc;
if(hasColorWindows)
fWindowPtr = GetNewCWindow(rWindowID, NULL, (WindowPtr)-1L);
else
fWindowPtr = GetNewWindow(rWindowID, NULL, (WindowPtr)-1L);
if(fWindowPtr)
{
fNextHandler = fDoc;
SetWRefCon(fWindowPtr, (long)this); // tie this to window for activate events!!
if(prevFrontWindow != NULL)
MoveWindow(fWindowPtr, corner.h + kStagger, corner.v + kStagger, TRUE);
ShowWindow(fWindowPtr);
return TRUE;
}
else
{
KillMeNext();
return FALSE;
}
}
void DWindow::Draw( Rect *area)
{
EraseRect(area);
}
void DWindow::HandleUpdateEvt(EventRecord *theEvent)
{
SetPort (fWindowPtr);
BeginUpdate (fWindowPtr);
if( !EmptyRgn(fWindowPtr->visRgn) )
Draw( &(fWindowPtr->portRect));
DrawGrowIcon( fWindowPtr);
EndUpdate(fWindowPtr);
inherited::HandleUpdateEvt(theEvent);
}
void DWindow::HandleActivateEvt(EventRecord *theEvent)
{
Boolean activating;
FocusOnContent();
if( !EmptyRgn(fWindowPtr->visRgn) )
Draw( &(fWindowPtr->portRect));
DrawGrowIcon(fWindowPtr);
inherited::HandleActivateEvt(theEvent);
}
void DWindow::Close(void)
{
fDoc->WindowClosed(this);
KillMeNext();
}
void DWindow::KillMeNext(void)
{
if(fAlive)
{
inherited::KillMeNext();
fDoc->WindowClosed(this);
DisposeWindow( fWindowPtr );
}
}
void DWindow::HandleMouseDown(EventRecord *theEvent, short thePart, WindowPtr theWindow)
{
if (theWindow == fWindowPtr)
{
switch( thePart)
{
case inGoAway:
if (TrackGoAway(theWindow, theEvent->where) )
Close();
break;
case inDrag:
DoDrag(theEvent);
break;
case inGrow:
DoGrow(theEvent);
break;
case inZoomIn:
case inZoomOut:
if( TrackBox( theWindow, theEvent->where, thePart) )
DoZoom(thePart);
break;
case inContent:
DoContent(theEvent);
break;
}// end switch
}
else
; // do nothing but pass it on
inherited::HandleMouseDown(theEvent, thePart, theWindow);
}
void DWindow::DoDrag(EventRecord *theEvent)
{
RgnHandle theGrayRgn;
Rect r;
theGrayRgn = GetGrayRgn();
r = (**theGrayRgn).rgnBBox;
DragWindow(fWindowPtr, theEvent->where, &r);
}// end member function DoDrag
void DWindow::DoGrow(EventRecord *theEvent)
{
long result;
RgnHandle theGrayRgn;
Rect r;
theGrayRgn = GetGrayRgn();
r = (**theGrayRgn).rgnBBox;
r.top = MINHIGHT; r.left = MINWIDTH;
SetPort(fWindowPtr);
result = GrowWindow(fWindowPtr, theEvent->where, &r);
if(result != 0)
{
r = fWindowPtr->portRect;
r.left = r.right - kScrollBarPos;
InvalRect(&r);
EraseRect(&r);
r = fWindowPtr->portRect;
r.top = r.bottom - kScrollBarPos;
InvalRect(&r);
EraseRect(&r);
SizeWindow(fWindowPtr, LoWrd(result), HiWrd(result), TRUE);
r = fWindowPtr->portRect;
r.left = r.right - kScrollBarPos;
InvalRect(&r);
EraseRect(&r);
r = fWindowPtr->portRect;
r.top = r.bottom - kScrollBarPos;
InvalRect(&r);
EraseRect(&r);
}// end if
}// end of member function DoGrow
void DWindow::DoZoom(short thePart)
{
SetPort(fWindowPtr);
EraseRect(&fWindowPtr->portRect);
ZoomWindow(fWindowPtr, thePart, fWindowPtr == FrontWindow());
InvalRect(&fWindowPtr->portRect);
}// end member function DoZoom
void DWindow::DoContent(EventRecord *theEvent)
{
; // stub!!
}// end member function DoContent
void DWindow::DoPageSetUp(void)
{
PrOpen();
(void)PrStlDialog(fPrintRecord);
PrClose();
}
void DWindow::DoPrint(void)
{
TPPrPort printPort;
Rect r;
TPrStatus status;
THPrint tmpPrintRecord;
tmpPrintRecord = fPrintRecord;
PrOpen();
if (PrValidate(tmpPrintRecord) )
if (!PrStlDialog(tmpPrintRecord) )
{
PrClose();
return;
}
if (!PrJobDialog(tmpPrintRecord) )
{
PrClose();
return;
}
printPort = PrOpenDoc(tmpPrintRecord, NULL, NULL);
PrOpenPage(printPort, NULL);
SetRect(&r, 0, 0, 0, 0);
Draw(&r);
PrClosePage(printPort);
PrCloseDoc(printPort);
if ((**tmpPrintRecord).prJob.bJDocLoop != 0)
PrPicFile(tmpPrintRecord, NULL, NULL, NULL, &status);
PrClose();
// now clean up the mess we made on the screen!!!
FocusOnWindow();
InvalRgn( ((WindowPeek)fWindowPtr)->contRgn);
}
void DWindow::SetWindowTitle(void)
{
StringPtr title;
if(fDoc->fFileRef != 0) //fFileRef is the file open flag.
{
title = (fDoc->fFileReply->sfFile).name;
SetWTitle(fWindowPtr, title);
}
}
void DWindow::FocusOnContent(void)
{
Rect r;
SetPort(fWindowPtr);
SetOrigin(fHOffSet, fVOffSet);
GetContentRect(&r);
ClipRect(&r);
}/*end of function*/
void DWindow::FocusOnWindow(void)
{
Rect r;
SetPort(fWindowPtr);
SetOrigin(0,0);
r = fWindowPtr->portRect;
ClipRect(&r);
}/*end of function*/
void DWindow::GetContentRect(Rect *r)
{
*r = fWindowPtr->portRect;
r->right -= kScrollBarPos;
r->bottom -= kScrollBarPos;
}/*end of function*/